package com.github.link2fun.support.exception;

import lombok.Getter;

import java.io.Serial;

/**
 * 业务异常
 *
 * @author ruoyi
 */
@Getter
public final class ServiceException extends RuntimeException {
  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 错误码
   */
  private Integer code;

  /**
   * 错误提示
   */
  private String message;

  /** 错误明细，内部调试错误 */
  private String detailMessage;

  /** 空构造方法，避免反序列化问题 */
  public ServiceException() {
  }

  public ServiceException(String message) {
    this.message = message;
  }

  public ServiceException(String message, Integer code) {
    this.message = message;
    this.code = code;
  }

  @Override
  public String getMessage() {
    return message;
  }

  public ServiceException withMessage(String message) {
    this.message = message;
    return this;
  }

  public ServiceException withDetailMessage(String detailMessage) {
    this.detailMessage = detailMessage;
    return this;
  }
}